<?php

use swap\service_except;

class resume_except extends service_except {}

class resume_service extends swap\service {
    
    public static function new_resume_for($user_id) {
        # 更新user_limit
        user_limit_model::inc(array('resume_count' => 1), array('user_id' => $user_id));
        
        # 插入resume
        $user_info = user_info_model::get_one(array('user_id' => $user_id));
        $add = array('user_id' => $user_id);
        if ($user_info !== null) {
            $add['degree'] = resume_model::degree_user_info;
        }
        $id = resume_model::add($add);
        
        # 插入resume_ext
        $add = array('resume_id' => $id);
        if ($user_info !== null) {
            $add['user_info_id'] = json_encode(array($user_info->id));
        }
        resume_ext_model::add($add);
        
        return $id;
    }
    
    /**
     * 0-5 全灰
     * 10-15-20 亮1
     * 25-30-35-40 亮2
     * 45-50-55-60 亮3
     * 65-70-75-80-85-90 亮4
     * 95-100 亮5
     */
    public static function five_stars_status($resume_degree) {
        $show = true;
        
        // 根据分数显示
        if ($resume_degree >= 0 && $resume_degree <= 5) { // 全灰
            $five_stars_status = array(!$show, !$show, !$show, !$show, !$show);
        } else if ($resume_degree > 5 && $resume_degree <= 20) { // 亮1
            $five_stars_status = array($show, !$show, !$show, !$show, !$show);
        } else if ($resume_degree > 20 && $resume_degree <= 40) { // 亮2
            $five_stars_status = array($show, $show, !$show, !$show, !$show);
        } else if ($resume_degree > 40 && $resume_degree <= 60) { // 亮3
            $five_stars_status = array($show, $show, $show, !$show, !$show);
        } else if ($resume_degree > 61 && $resume_degree <= 90) { // 亮4
            $five_stars_status = array($show, $show, $show, $show, !$show);
        } else { // 亮5
            $five_stars_status = array($show, $show, $show, $show, $show);
        }
        return $five_stars_status;
    }
    
}